package com.katesoft.scale4j.persistent.config;

import com.atomikos.icatch.config.UserTransactionServiceImp;
import com.katesoft.scale4j.common.lang.RuntimeUtility;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import java.util.Properties;

/**
 * Add some local default configurations.(no additional logic)
 *
 * @author kate2007
 */
public class UserTransactionService extends UserTransactionServiceImp implements InitializingBean, DisposableBean
{
    /**
     * add output_dir location to DATA_DIR(this property can be injected via System parameters)
     *
     * @param properties client properties
     */
    public UserTransactionService(final Properties properties)
    {
        super(new Properties()
        {
            {
                if (!properties.contains("com.atomikos.icatch.output_dir")) {
                    put("com.atomikos.icatch.output_dir", RuntimeUtility.TM_DATA_DIR);
                }
                if (!properties.contains("com.atomikos.icatch.log_base_dir")) {
                    put("com.atomikos.icatch.log_base_dir", RuntimeUtility.TM_DATA_DIR);
                }
                putAll(properties);
            }
        });
    }

    @Override
    public void afterPropertiesSet() throws Exception
    {
        init();
    }

    @Override
    public void destroy() throws Exception
    {
        super.shutdownForce();
    }
}
